package cn.itcast.demo.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
@EnableConfigurationProperties(JdbcProperties.class)//配置类引用属性类，用来从属性类中取值
public class JdbcConfigSpringboot {


//    @Autowired
//    private JdbcProperties jdbcProperties;


    @Bean
    public DataSource dataSource(JdbcProperties jdbcProperties) {

        DruidDataSource dataSource = new DruidDataSource();

        dataSource.setDriverClassName(jdbcProperties.getDriverClassName());

        dataSource.setUrl(jdbcProperties.getUrl());

        dataSource.setUsername(jdbcProperties.getUsername());

        dataSource.setPassword(jdbcProperties.getPassword());
        return dataSource;
    }


}
